﻿using System;
namespace Producers.Etoimik.Xtee.Riik.Ee.Producer.Etoimik {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="KOLAAsi", Namespace="http://producers.etoimik.xtee.riik.ee/producer/etoimik", Target=typeof(KOLAAsi))]
    public class KOLAAsiSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IKOLAAsi clazz;
        
        public KOLAAsiSerializer(IKOLAAsi clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            if (clazz.AlustatudKP!=null) {
                Writer.WriteStartElement("AlustatudKP");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.AlustatudKP))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.AsjaKategooria!=null) {
                Writer.WriteStartElement("AsjaKategooria");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.AsjaKategooria))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.AsjaKood!=null) {
                Writer.WriteStartElement("AsjaKood");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "int");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdInt(((int)(clazz.AsjaKood))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.AsjaLiik!=null) {
                Writer.WriteStartElement("AsjaLiik");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.AsjaLiik))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.AsjaNumber!=null) {
                Writer.WriteStartElement("AsjaNumber");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.AsjaNumber))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.AstmeStaatus!=null) {
                Writer.WriteStartElement("AstmeStaatus");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.AstmeStaatus))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Kohtunik!=null) {
                Writer.WriteStartElement("Kohtunik");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Kohtunik))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Kohus!=null) {
                Writer.WriteStartElement("Kohus");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Kohus))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.LahendiKP!=null) {
                Writer.WriteStartElement("LahendiKP");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "dateTime");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdDateTime(((System.DateTime)(clazz.LahendiKP))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.MenetlusaluneOsaline!=null) {
                Writer.WriteStartElement("MenetlusaluneOsaline");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.MenetlusaluneOsaline))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Menetlused!=null) {
                Writer.WriteStartElement("Menetlused");
                Writer.WriteTypeAttribute("http://schemas.xmlsoap.org/soap/encoding/", "Array");
                Writer.WriteArrayTypeAttribute("KOLAMenetlus", "http://producers.etoimik.xtee.riik.ee/producer/etoimik", clazz.Menetlused.Count);
                for (int x = 0; ((clazz.Menetlused != null) 
                            && (x < clazz.Menetlused.Count)); x = (x + 1)) {
                    if (clazz.Menetlused[x]!=null) {
                        Writer.WriteStartElement("item");
                        global::Xtee.Core.SerializationMetadata metaMenetlused = this.GetMetaData(clazz.Menetlused[x]);
                        Writer.WriteTypeAttribute(metaMenetlused.TypeQualifiedName.Namespace, metaMenetlused.TypeQualifiedName.Name);
                        metaMenetlused.NewSerializer(clazz.Menetlused[x]).WriteXml(Writer);
                        Writer.WriteEndElement();
                    }
                }
                Writer.WriteEndElement();
            }
            if (clazz.MenetluseKood!=null) {
                Writer.WriteStartElement("MenetluseKood");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "int");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdInt(((int)(clazz.MenetluseKood))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Osaline!=null) {
                Writer.WriteStartElement("Osaline");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Osaline))).ToString());
                Writer.WriteEndElement();
            }
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="AlustatudKP") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.AlustatudKP = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("AlustatudKP")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="AsjaKategooria") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.AsjaKategooria = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("AsjaKategooria")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="AsjaKood") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.AsjaKood = new global::Xtee.Core.Schema.XsdInt(Reader.ReadElementString("AsjaKood")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="AsjaLiik") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.AsjaLiik = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("AsjaLiik")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="AsjaNumber") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.AsjaNumber = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("AsjaNumber")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="AstmeStaatus") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.AstmeStaatus = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("AstmeStaatus")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="Kohtunik") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.Kohtunik = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Kohtunik")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="Kohus") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.Kohus = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Kohus")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="LahendiKP") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.LahendiKP = new global::Xtee.Core.Schema.XsdDateTime(Reader.ReadElementString("LahendiKP")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="MenetlusaluneOsaline") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.MenetlusaluneOsaline = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("MenetlusaluneOsaline")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="Menetlused") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.Menetlused = new System.Collections.Generic.List<global::Producers.Etoimik.Xtee.Riik.Ee.Producer.Etoimik.IKOLAMenetlus>();
                    if ((Reader.IsEmptyElement == false)) {
                        Reader.ReadStartElement("Menetlused");
                        for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                                    && (Reader.LocalName == "item")); ) {
                            if ((Reader.IsElementNil() == false)) {
                                global::Xtee.Core.SerializationMetadata metaMenetlused = this.GetMetaData<global::Producers.Etoimik.Xtee.Riik.Ee.Producer.Etoimik.IKOLAMenetlus>(Reader, "KOLAMenetlus", "http://producers.etoimik.xtee.riik.ee/producer/etoimik");
                                global::Producers.Etoimik.Xtee.Riik.Ee.Producer.Etoimik.IKOLAMenetlus item = metaMenetlused.NewEntity<global::Producers.Etoimik.Xtee.Riik.Ee.Producer.Etoimik.IKOLAMenetlus>();
                                clazz.Menetlused.Add(item);
                                if ((Reader.IsEmptyElement == false)) {
                                    Reader.ReadStartElement("item");
                                    metaMenetlused.NewSerializer(item).ReadXml(Reader);
                                    Reader.ReadEndElement();
                                }
                                else {
                                    Reader.Skip();
                                }
                            }
                            else {
                                clazz.Menetlused.Add(null);
                                Reader.Skip();
                            }
                        }
                        Reader.ReadEndElement();
                    }
                    else {
                        Reader.Skip();
                    }
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="MenetluseKood") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.MenetluseKood = new global::Xtee.Core.Schema.XsdInt(Reader.ReadElementString("MenetluseKood")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="Osaline") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.Osaline = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Osaline")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
        }
    }
}
